/**
 * Created by dale on 2017/8/9.
 */
$(document).ready(function () {
    var list= $('#List'),
        startDom    = $('#List_Search_StartTime'),
        endDom      = $('#List_Search_EndTime');

    startDom.datebox();
    endDom.datebox();

    startDom.datebox('setValue', GetDateStr(-7));
    endDom.datebox('setValue', GetDateStr(0));

    var startTime   = startDom.getElementValue(),
        endTime     = endDom.getElementValue();
    $('.xh-datagrid-toolbar').parseToolbar();

    list.initDataGrid(baseUrl + 'customer/getIntentRoute',{queryParams:{startTime:startTime,endTime:endTime}});

    DataGrid.onLoadSuccess = function(data){
        if (data.rows.length > 0) {
            list.mergeCellsByField(['tTime']);
        }
    };

    $('#excel_export').click(function () {
        var startTime   = startDom.getElementValue(),
            endTime     = endDom.getElementValue(),
            key         =xhExtra.getValue($('#list_search'));
        var select_content=xhExtra.getValue($('#select_content'));
        window.open(baseUrl+'customer/exportIntentRoute?startTime='+startTime+'&endTime='+endTime+'&key='+key+'&content='+select_content);
        $('#bt_list_search').click();
    });

    $('#bt_list_search').click(function () {
        var startTime   = startDom.getElementValue(),
            endTime     = endDom.getElementValue(),
            key         =xhExtra.getValue($('#list_search'));
        if(!startTime || !endTime){
            window.top.xhTop.showError('错误','时间不可为空！');
            return false;
        }
        var select_content=xhExtra.getValue($('#select_content'));
        list.addDataGridParams({key:key,startTime:startTime,endTime:endTime,content:select_content});
    });

    
});
function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth()+1;//获取当前月份的日期
    var d = dd.getDate();
    return y+"-"+m+"-"+d;
}